package com.biboheart.breport.template.struct;

import com.biboheart.breport.template.BrTemplateNode;
import com.biboheart.breport.template.BrTemplateStruct;
import com.biboheart.breport.template.BrTemplateStructSetter;
import com.biboheart.breport.template.node.BrTemplateNodeCol;
import com.biboheart.brick.utils.CheckUtils;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

public class BrTemplateStructDefault implements BrTemplateStruct, BrTemplateStructSetter {
    private final List<BrTemplateNode> colList = new ArrayList<>();
    private final List<BrTemplateNode> parameterList = new ArrayList<>();

    @Override
    public List<BrTemplateNode> getCols() {
        return colList;
    }

    @Override
    public List<BrTemplateNode> getParameter() {
        return parameterList;
    }

    @Override
    public void setColList(List<BrTemplateNode> colList) {
        this.colList.clear();
        this.colList.addAll(colList);
    }

    @Override
    public void setParameterList(List<BrTemplateNode> parameterList) {
        this.parameterList.clear();
        this.parameterList.addAll(parameterList);
    }

    @Override
    public void convertColList(List<Map<String, Object>> list) {
        colList.clear();
        if (CheckUtils.isEmpty(list)) {
            return;
        }
        for (Map<String, Object> data : list) {
            BrTemplateNodeCol colNode = new BrTemplateNodeCol();
            colNode.convert(data);
            colList.add(colNode);
        }
    }

    @Override
    public void convertParameterList(List<Map<String, Object>> list) {
        parameterList.clear();
    }
}
